﻿/******************************************************************************
* File description: BoxTimeWaterAirPump.qml
* Function: 主页操作水泵/气泵时弹出来的窗口
* Current Version: 1.0.0
* Author: JNN
* Date: 2025-07-01
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
import QtQuick 2.0
import "../components"

CustomPopupBox {

    id: root

    height: 300*dp
    width: 400*dp
    title: "转液配置"

    property int minSpeed: 100
    property int maxSpeed: 700
    property int type: gPageIdx

    onVisibleChanged: {
        combo_op.setIndex(0)
        edit_speed.setText("")
        edit_time.setText("")
    }

    contentItem: Item{

        Column{
            spacing: 12*dp
            anchors.centerIn: parent
            CustomComboBox{
                id: combo_op
                title: "动作"
                titleWidth: 120*dp
                model: type === 3 ? ["打液", "吸液", "关闭"] : ["打液", "关闭"]
            }
            CustomInputText{
                id: edit_speed
                titleWidth: 120*dp
                title: "速度("+minSpeed.toString()+"-"+maxSpeed.toString()+"r/m)"
                intflag: true
                editable: combo_op.getText() !== "关闭"
            }CustomInputText{
                id: edit_time
                titleWidth: 120*dp
                title: "时间(s)"
                editable: combo_op.getText() !== "关闭"
            }
            Item{ height: 1*dp; width: 1*dp }
            Row{
                y: type===0 ? 135*dp : 90*dp
                spacing: 15*dp
                anchors.horizontalCenter: parent.horizontalCenter
                CustomButton{
                    title: "取消"
                    width: 100*dp
                    defaultMode2: true
                    onClicked: {
                        root.close()
                    }
                }CustomButton{
                    title: "确定"
                    width: 100*dp
                    defaultMode1: true
                    onClicked: {

                        if(combo_op.getText()!=="关闭" && (edit_speed.getText()==="" || Number(edit_speed.getText())===0)){
                            box_error_common.box_text = "请正确填写速度"
                            box_error_common.show()
                            return
                        }
                        if(combo_op.getText()!=="关闭" && (edit_time.getText()==="" || Number(edit_time.getText())===0)){
                            box_error_common.box_text = "请正确填写时长"
                            box_error_common.show()
                            return
                        }

                        if(type === 3){
                            gStateOp.openPopup("2C", [])
                            if(combo_op.getText() === "关闭"){
                                CommunicationMethod.stepOperatingSimulation("3","6",[combo_op.getText(), "", ""])
                            }else{
                                CommunicationMethod.stepOperatingSimulation("3","6",[combo_op.getText(), edit_speed.getText(), edit_time.getText()])
                            }
                        }
                        else if(type === 4){
                            gStateOp.openPopup("05", [])
                            if(combo_op.getText() === "关闭"){
                                CommunicationMethod.stepOperatingSimulation("4","6",[combo_op.getText(), "", ""])
                            }else{
                                CommunicationMethod.stepOperatingSimulation("4","6",[combo_op.getText(), edit_speed.getText(), edit_time.getText()])
                            }
                        }
                        root.close()
                    }
                }
            }
        }


    }

}
